package com.example.aqarapp.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Display;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import aqarapp.R;

public class UserInfoDialog extends Dialog {

    private Context mContext;
    private Point mWindowSize = new Point();
    private TextView textTermsTitle, textTermsMsg;
    private String title;
    private String content;

    public UserInfoDialog(@NonNull Context context) {
        super(context);
        mContext = context;

    }

    public UserInfoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected UserInfoDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public UserInfoDialog(@NonNull Context context, String title, String content) {
        super(context);
        mContext = context;
        this.title = title;
        this.content = content;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_info_dialog);
        WindowManager windowManager = ((Activity) mContext).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        display.getSize(mWindowSize);
        lp.width = mWindowSize.x * 4 / 5;// 设置dialog宽度为屏幕的4/5
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(true);//点击外部Dialog消失
        initDialogContent();

    }

    private void initDialogContent() {
        textTermsTitle = findViewById(R.id.user_info_dialog_title_tv);
        textTermsMsg = findViewById(R.id.user_info_dialog_content_tv);
        textTermsMsg.setMovementMethod(ScrollingMovementMethod.getInstance());
        setDialogTitleAndDetail(title, content);
    }

    private void setDialogTitleAndDetail(String title, String content) {
        textTermsTitle.setText(title);
        textTermsMsg.setText(content);
    }
}
